# Contributor: Kevin Daudt <kdaudt@alpinelinux.org>
# Maintainer: Kevin Daudt <kdaudt@alpinelinux.org>

_kver=5.4.54
_krel=2
_flavor="$FLAVOR"
[ -z "$_flavor" ] && _flavor=lts

_commit=18c1f607c10307a249be82cb398fb08eb7857a9f
_rel=1
_kpkg=linux-$_flavor

pkgname="rtl8821ce-lts"
pkgver="$_kver"
pkgrel=$((_krel + _rel))
pkgdesc="Wifi drivers for Realtek 8821ce"
url="https://github.com/tomaspinho/rtl8821ce"
arch="x86_64 x86" # Only builds on these platforms
license="GPL-2.0-only"
makedepends="linux-lts-dev"
options="!check"
source="$pkgname-$_commit.tar.gz::https://github.com/tomaspinho/rtl8821ce/archive/$_commit.tar.gz"
builddir="$srcdir/rtl8821ce-$_commit"

prepare() {
	default_prepare

	if [ -z "$FLAVOR" ]; then
		(
			. "$startdir"/../../main/linux-$_flavor/APKBUILD
			[ "$_kver" != "$pkgver" ] && die "please update _kver to $pkgver"
			[ "$_krel" != "$pkgrel" ] && die "please update _krel to $pkgrel"
			return 0
		)
	fi
}

build() {
	make KVER=$_kver-$_krel-$_flavor \
		MODULES_DIR="/lib/modules/$_kver-$_krel-$_flavor"
}

package() {
	install -Dm0644 8821ce.ko \
		"$pkgdir"/lib/modules/$_kver-$_krel-$_flavor/extra/8821ce.ko
}

sha512sums="e0bdc7feaf7f29e760b86c2b85caf177e084c06fa681bb8888bf43927d766505d3573931ee878842089863eeefc25fee5107276dbde18375462c96600225f7ce  rtl8821ce-lts-18c1f607c10307a249be82cb398fb08eb7857a9f.tar.gz"
